package beans;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import forum.SubForum;
import forum.User;
import forum.db_code;
public class Hax {
	private SubForum[] subforum;
	public SubForum[] getSubforum() {
		db_code d = new db_code();
		List<SubForum> l = d.getAllSubForums();
		subforum = new SubForum[l.size()];
		for(int i = 0; i<l.size();i++){
			subforum[i] = l.get(i);
		}
		return subforum;
	}
	public void setSubforum(SubForum[] subforum) {
		this.subforum = subforum;
	}
	public Hax() {
		// TODO Auto-generated constructor stub
	}
	
	public User getUser(int userID){
		Connection conn = db_code.connect();
		try{
			Statement stmt = conn.createStatement();
			ResultSet rs = null;
			
			String query;
			query = "SELECT * FROM user WHERE userID="+userID+" LIMIT 1;";
			
			rs = stmt.executeQuery(query);
			
			User row = null;
			while(rs.next()){
				row  = new User(
						rs.getInt("userID"),
						rs.getInt("userlvl"),
						rs.getString("name"),
						rs.getString("email"),
						rs.getString("password"),
						rs.getTimestamp("joined"),
						rs.getInt("numberOfPosts")
						);
			}
			//disconnect();
			return row;
		}
		catch(SQLException e){
			System.out.println("SQL statement error!");
			e.printStackTrace();
		}
		return null;
	}
	
	
}
